package com.feiyuan.core.controller.admin;


import com.feiyuan.common.result.R;
import com.feiyuan.core.pojo.entity.AdminMenu;
import com.feiyuan.core.pojo.entity.AdminRoleMenu;
import com.feiyuan.core.service.AdminRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  角色授权前端控制器
 * </p>
 *
 * @author Xupf
 * @since 2022-09-06
 */
@Api("角色授权")
@RestController
@RequestMapping("/admin/core/adminRoleMenu")
//@CrossOrigin
public class AdminRoleMenuController {

    @Autowired
    private AdminRoleMenuService adminRoleMenuService;

    @ApiOperation("查询所有权限")
    @GetMapping("/listMenus")
    public R listMenus() {
        List<AdminMenu> menus = adminRoleMenuService.selectMenus();
        return R.ok().data("menus", menus);
    }

    @ApiOperation("根据角色ID查询所属权限")
    @GetMapping("/getByRoleId/{roleId}")
    public R getByRoleId(@PathVariable Long roleId) {
        List<Long> menuIds = adminRoleMenuService.getByRoleId(roleId);
        return R.ok().data("menuIds", menuIds);
    }

    @ApiOperation("保存或修改")
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody AdminRoleMenu adminRoleMenu) {
        adminRoleMenuService.saveOrUpdateMenus(adminRoleMenu);
        return R.ok();
    }
}

